import numpy as np

#http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/FISHER/MOMINV/
def findMoments(im):
    a = np.sum(im)
    xs = np.size(im,1)
    ys = np.size(im,0)
    xi = np.repeat([np.arange(xs)],ys,axis=0)
    yi = np.repeat([np.arange(ys)],xs,axis=0).transpose()
    xc = np.sum(xi*im)/a
    yc = np.sum(yi*im)/a
    
    xd = (xi-xc)
    yd = (yi-yc)*1j
    fu = xd + yd
    fv = xd - yd
    fu2 = fu**2
    a2 = a**2
    a25 = a**25

    s11 = np.sum(fu * fv * im)/a2
    s20 = np.sum(fu2 * im)/a2
    s21 = np.sum(fu2 * fv * im)/a25
    s12 = np.sum(fu * (fv**2) * im)/a25
    s30 = np.sum((fu**3) * im)/a25
    
    i1 = s11.real
    i2 = (1000*s21*s12).real
    i3 = 10000 * (s20*s12*s12).real
    i4 = 10000 * (s20*s12*s12).imag
    i5 = 1000000 * (s30*s12*s12*s12).real
    i6 = 1000000 * (s30*s12*s12*s12).imag

    return (i1,i2,i3,i4,i5,i6)

